package com.example.demo.common.com.example.demo;

public class Demo02 {

    public static void main(String[] args) {
        String s = null;
        int max = 1000000;
        for (int i = 0; i <= max; i++) {
            try {
                s.toString();
            } catch (NullPointerException e) {
                if (i == 0 || i == max) {
                    System.out.println("第"+ i +"次堆栈信息");
                    /**
                     * jvm参数增加-XX:-OmitStackTraceInFastThrow
                     * 否则只输出java.lang.NullPointerException，没有堆栈信息
                     */
                    e.printStackTrace();
                }
            }
        }
    }
}
